<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="日期" prop="roomName">
        <el-date-picker
          v-model="form.date"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="primary"-->
    <!--          icon="el-icon-plus"-->
    <!--          size="mini"-->
    <!--          @click="handleAdd"-->
    <!--          v-hasPermi="['mahjong:log:add']"-->
    <!--        >新增</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="success"-->
    <!--          icon="el-icon-edit"-->
    <!--          size="mini"-->
    <!--          :disabled="single"-->
    <!--          @click="handleUpdate"-->
    <!--          v-hasPermi="['mahjong:log:edit']"-->
    <!--        >修改</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="danger"-->
    <!--          icon="el-icon-delete"-->
    <!--          size="mini"-->
    <!--          :disabled="multiple"-->
    <!--          @click="handleDelete"-->
    <!--          v-hasPermi="['mahjong:log:remove']"-->
    <!--        >删除</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="warning"-->
    <!--          icon="el-icon-download"-->
    <!--          size="mini"-->
    <!--          @click="handleExport"-->
    <!--          v-hasPermi="['mahjong:log:export']"-->
    <!--        >导出</el-button>-->
    <!--      </el-col>-->
    <!--    </el-row>-->

    <el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
      <el-table-column label="店铺名称" align="center" prop="shopName" />
      <el-table-column label="操作员工" align="center" prop="staffName" />
      <el-table-column label="会员姓名" align="center" prop="name" />
     <!-- <el-table-column label="类型" align="center" prop="event" :formatter="statusFormat" />-->
     <el-table-column label="金额" align="center" prop="money" ></el-table-column>
      <el-table-column label="赠送金额" align="center" prop="sendMoney" />
      <el-table-column label="纯赠送" align="center" prop="onlySend" />
  <!--    <el-table-column label="积分" align="center" prop="integral" />-->
      <el-table-column label="操作信息" align="center" prop="operLog" />
    <!--  <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="操作时间" align="center" prop="createTime" />
      <!-- <el-table-column label="金额情况" align="center" prop="money" />-->

      <!--      <el-table-column type="selection" width="55" align="center" />-->
      <!--      <el-table-column label="预留3" align="center" prop="bak3" />-->
      <!--      <el-table-column label="预留2" align="center" prop="bak2" />-->
      <!--      <el-table-column label="预留1" align="center" prop="bak1" />-->
      <!--      <el-table-column label="店铺id" align="center" prop="shopId" />-->





      <!--      <el-table-column label="id" align="center" prop="id" />-->
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-edit"-->
      <!--            @click="handleUpdate(scope.row)"-->
      <!--            v-hasPermi="['mahjong:log:edit']"-->
      <!--          >修改</el-button>-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-delete"-->
      <!--            @click="handleDelete(scope.row)"-->
      <!--            v-hasPermi="['mahjong:log:remove']"-->
      <!--          >删除</el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户操作记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="预留3" prop="bak3">
          <el-input v-model="form.bak3" placeholder="请输入预留3" />
        </el-form-item>
        <el-form-item label="预留2" prop="bak2">
          <el-input v-model="form.bak2" placeholder="请输入预留2" />
        </el-form-item>
        <el-form-item label="预留1" prop="bak1">
          <el-input v-model="form.bak1" placeholder="请输入预留1" />
        </el-form-item>
        <el-form-item label="店铺id" prop="shopId">
          <el-input v-model="form.shopId" placeholder="请输入店铺id" />
        </el-form-item>
        <el-form-item label="积分情况" prop="integral">
          <el-input v-model="form.integral" placeholder="请输入积分情况" />
        </el-form-item>
        <el-form-item label="金额情况" prop="money">
          <el-input v-model="form.money" placeholder="请输入金额情况" />
        </el-form-item>
        <el-form-item label="事件" prop="event">
          <el-input v-model="form.event" placeholder="请输入事件" />
        </el-form-item>
        <el-form-item label="操作员工id" prop="staffId">
          <el-input v-model="form.staffId" placeholder="请输入操作员工id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listLog, getLog, delLog, addLog, updateLog, exportLog } from "@/api/mahjong/log";

  export default {
    name: "Log",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 用户操作记录表格数据
        logList: [],
        statusOptions:[],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          bak3: undefined,
          bak2: undefined,
          bak1: undefined,
          event:'1',
          orderByColumn:'w.id',
          isAsc:'desc',
          shopId: undefined,
          integral: undefined,
          money: undefined,
          event: undefined,
          staffId: undefined,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();

      this.getDicts("member_oper_type").then(response => {
        this.statusOptions = response.data;
      });
    },
    methods: {
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.event);
      },
      /** 查询用户操作记录列表 */
      getList() {
        this.loading = true;
        if(this.form.date){
          this.queryParams.startTime=this.form.date[0]
          this.queryParams.endTime=this.form.date[1]
        }
        listLog(this.queryParams).then(response => {
          this.logList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          updateBy: undefined,
          updateTime: undefined,
          createBy: undefined,
          createTime: undefined,
          bak3: undefined,
          bak2: undefined,
          bak1: undefined,
          shopId: undefined,
          integral: undefined,
          money: undefined,
          event: undefined,
          staffId: undefined,
          id: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加用户操作记录";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getLog(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改用户操作记录";
        });
      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != undefined) {
              updateLog(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.msgError(response.msg);
                }
              });
            } else {
              addLog(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.msgError(response.msg);
                }
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除用户操作记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delLog(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有用户操作记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportLog(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      }
    }
  };
</script>
